<?php
/**
 * 网站首页控制器
 *
 */
class IndexAction extends Action {

	/**
	 * 网站统一配置
	 *
	 * @var unknown_type
	 */
	public $Config;

	/**
	 * 构造函数
	 *
	 */
	public function _initialize()
	{
		$Config = D('Config');
		$this->Config = $Config->find('config_id=1');
	}
	
    public function Show() {
        //获取热门资讯
        $Article = D('Article');
        $HotArticle = $Article->where('cid=1')->order('article_id desc')->limit(14)->findall();
        //获取本站服务
        $conditions = array();
        $conditions['cid'] = 1;
        $Infoclass = D('Info');
        $Info = $Infoclass->where($conditions)->order('info_order desc,iid desc')->top(8);

        //获取最近加入
        $Enterprise = D('Enterprise');
        $NewsEnterprise = $Enterprise->order('enter_id desc')
								        ->field('enter_id,domain,name,created')
								        ->top(6);

        //获取所有推荐企业
        //$Recommend = D('Enterprise');
        $TeseFont = $Enterprise->where('re_id=1')->order('enterprise_order desc,enter_id desc')->xfindall();
		$TeseImg = $Enterprise->where('re_id=9')->order('enterprise_order desc,enter_id desc')->xfindall();
		//企业产品
		$Eproduct = D('Eproducts');
		$IndexProduct = $Eproduct->field('pid,name,bimg,enter_id')
									->order('pid desc')
									->limit(8)
									->findall();
		
		//获取企业资讯
		$Einfos = D('Einfoservices');
		$EnterpriseNews = $Einfos
							->where('cid=15 and einfos_audit=\'Y\'')
							->order('einfos_top desc,einfos_sort desc,einfos_id desc')
							->field('einfos_id,id,enter_id,einfos_top,einfos_sort,einfos_link,einfos_linkaddress,title')
							->limit(15)
							->xfindall();
		//获取供求信息
		$GQ = $Einfos->where('cid=1 and einfos_audit=\'Y\'')
					->order('einfos_top desc,einfos_sort desc,einfos_id desc')
					->field('einfos_id,id,enter_id,einfos_top,einfos_sort,einfos_link,einfos_linkaddress,title')
					->limit(15)
					->xfindall();
		//企业家访谈
		$InterviewDB = D('Interview');
		$Interview = $InterviewDB->field('iid,name,core,img')
								->order('interview_sort desc,iid desc')
								->limit(4)
								->findall();

		//特色教育
		$Edu = $Enterprise->where('cid=15')
						->order('enterprise_order desc,enter_id desc')
						->field('enter_id,name,enote,logo')
						->find();
		/**
		 * 特色装饰
		 */
		$De = $Enterprise->where('re_id=8 and cid=22')
						->order('enterprise_order desc,enter_id desc')
						->field('enter_id,name,domain')
						->top4();
		/**
		 * 东营汽车
		 */
		$Car = $Enterprise->where('re_id=4 and cid=40')
						->order('enterprise_order desc,enter_id desc')
						->field('enter_id,domain,enterprise_order,name')
						->top10();
		//项目合作
		$Hezuo = $Einfos
							->where('cid=3 and einfos_audit=\'Y\'')
							->order('einfos_top desc,einfos_sort desc,einfos_id desc')
							->field('einfos_id,id,enter_id,einfos_top,einfos_sort,einfos_link,einfos_linkaddress,title')
							->limit(15)
							->xfindall();
		//招聘求职
		$Jobs = $Einfos
							->where('cid=4 and einfos_audit=\'Y\'')
							->order('einfos_top desc,einfos_sort desc,einfos_id desc')
							->field('einfos_id,id,enter_id,einfos_top,einfos_sort,einfos_link,einfos_linkaddress,title')
							->limit(15)
							->xfindall();
		//特色产业 - 图标
		$TeseChanyeLogo = $Enterprise->where('re_id=11')
							->order('enterprise_order desc,enter_id desc')
							->field('enter_id,domain,enterprise_order,name,logo')
							->top4();
		$TeseChanyeFont = $Enterprise->where('re_id=10')
							->order('enterprise_order desc,enter_id desc')
							->field('enter_id,domain,enterprise_order,name')
							->top4();
        //获取友情链接
        $link = D('Friendlinks');
        $Friendlinks1 = $link->where('cid=1')->order('links_order desc,fid desc')->limit(18)->findall();
        $Friendlinks2 = $link->where('cid=2')->order('links_order desc,fid desc')->limit(18)->findall();
        //To templates
        $this->assign('Config',$this->Config);
        $this->assign('HotArticle',$HotArticle);//热门资讯
        $this->assign('Info',$Info);//本站服务
        $this->assign('NewsEnterprise',$NewsEnterprise);//最新加入
        $this->assign('TeseFont',$TeseFont);//特色企业
        $this->assign('IndexProduct',$IndexProduct);//最新产品
        $this->assign('EnterpriseNews',$EnterpriseNews);//企业资讯
        $this->assign('GQ',$GQ);//供求信息
        $this->assign('Interview',$Interview);//访谈
        $this->assign('Edu',$Edu);//特色教育
        $this->assign('De',$De);//特色装饰
        $this->assign('Car',$Car);//东营汽车
        $this->assign('Hezuo',$Hezuo);//项目合作
        $this->assign('Jobs',$Jobs);//招聘求职
        $this->assign('TeseChanyeLogo',$TeseChanyeLogo);//特色产业Logo
        $this->assign('TeseChanyeFont',$TeseChanyeFont);//特色产业字
        $this->assign('TeseImg',$TeseImg);
        $this->assign('Friendlinks1',$Friendlinks1);//合作伙伴
        $this->assign('Friendlinks2',$Friendlinks2);//友情链接
        $this->display();
    }
	/**
	 * 获取状态{:url('VipIndex','Euser')}
	 */
    public function GetState()
    {
    	if ($_SESSION['Q'] != '') {
    		//echo "document.write(\'<A href='".url('VipIndex','Euser')."'>进入管理</A>\')";
    		echo "document.write('<A href=\'".url('VipIndex','Euser')."\'>进入管理</A>')";
    	}
    }
    /**
     * 跳转
     */
    public function EShow()
    {
    	//获取企业数据
    	$Input = Input::getInstance();
    	$Input->filter('addslashes');
    	
    	import('ORG.Util.HashMap');
    	$conditions = new HashMap();
    	$conditions->put('domain',array('EQ',$Input->get('domain')));
    	
    	//从数据库 获取 企业信息
    	$Enterprise = D('Enterprise');
    	$count = $Enterprise->count($conditions,'enter_id');
    	//如果符合条件的用户为0
    	if ($count == 0) {
    		$this->redirect('Show','Index');
    	}
    	$Enter = $Enterprise->where($conditions)->find();

    	//组成模板 xxx@Index:Show
    	$UserTpl = $Enter['templates'] . '@Index:Show';
    	
    	//获取要最新资讯
    	$Infos = D('Einfoservices');
    	$I = $Infos->field('einfos_id,id,title,created')->where("einfos_audit='Y' and enter_id=".$Enter['enter_id'])->limit(2)->xfindall();
    	
    	//获取企业简介
    	$About = D('Enterpriseabout');
    	$AboutContent = $About->where('enter_id='.$Enter['enter_id'])->find();
    	
    	//获取最新产品
    	$Product = D('Eproducts');
    	$P = $Product->where('enter_id='.$Enter['enter_id'])
				    	->field('pid,name,bimg,content')
				    	->top2();
    	
    	$this->assign('Enterprise',$Enter);
    	$this->assign('About',$AboutContent);
    	$this->assign('Products',$P);
    	$this->assign('Infos',$I);
    	$this->assign('enter_id',$Enter['enter_id']);
    	$this->assign('Config',$this->Config);
    	$this->display($UserTpl);
    }
}